package day17.homework2;

import lombok.SneakyThrows;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class UdpClient {
    @SneakyThrows
    public static void main(String[] args) {
        File file = new File("D:\\图片视频\\jmj.jpg");
        SocketAddress address = new InetSocketAddress("127.0.0.1", 1000);
        try (DatagramSocket datagramSocket = new DatagramSocket();
             InputStream is = new FileInputStream(file)) {
            int len = 0;
            byte[] data = new byte[1024];
            while ((len = is.read(data)) != -1) {
                DatagramPacket datagramPacket = new DatagramPacket(data, len, address);
                datagramSocket.send(datagramPacket);
            }
        }
    }
}
